import request from '@/config/axios'

// 能耗数据 VO
export interface DataVO {
  id: number // 主键ID
  deviceId: string // 设备ID
  deviceName: string // 设备名称
  timestamp: Date // 数据时间戳
  voltage: number // 电压(V)
  currents: number // 电流(A)
  activePower: number // 功率(kW)
  energyConsumption: number // 累计能耗(kWh)
  temperature: number // 设备温度(℃)
  status: string // 状态
}

// 能耗数据 API
export const DataApi = {
  // 查询能耗数据分页
  getDataPage: async (params: any) => {
    return await request.get({ url: `/energy/data/page`, params })
  },

  // 查询能耗数据详情
  getData: async (id: number) => {
    return await request.get({ url: `/energy/data/get?id=` + id })
  },

  // 新增能耗数据
  createData: async (data: DataVO) => {
    return await request.post({ url: `/energy/data/create`, data })
  },

  // 修改能耗数据
  updateData: async (data: DataVO) => {
    return await request.put({ url: `/energy/data/update`, data })
  },

  // 删除能耗数据
  deleteData: async (id: number) => {
    return await request.delete({ url: `/energy/data/delete?id=` + id })
  },

  // 导出能耗数据 Excel
  exportData: async (params) => {
    return await request.download({ url: `/energy/data/export-excel`, params })
  },

  // 获取所有设备列表
  getDeviceList: async () => {
    return await request.get({ url: '/energy/data/list-devices' })
  }
}
